<?php
class uicompentControl extends skymvc{
	
	public function __construct(){
		parent::__construct();
	}
	
	public function onDefault(){
		$where="  status=2";
		$url="/admin.php?m=uicompent";
		$option=array(
			"where"=>$where
		);
		$rscount=true;
		$data=M("uicompent")->select($option,$rscount);
		 
		$this->smarty->goAssign(array(
			"data"=>$data,		 
		));
		$this->smarty->display("uicompent/index.html");
	}
	
	public function onAdd(){
		$id=get("id",'i');
		$data=array();
		if($id){
			$data=M("uicompent")->selectRow("id=".$id);
			$data['jsondata']=base64_decode($data['jsondata']);
		}
		$this->smarty->goAssign(array(
			"data"=>$data
		));
		$this->smarty->display("uicompent/add.html");
	}
	
	public function onSave(){
		$id=get_post("id");
		$data['title']=post("title","h");
		$data['description']=$_POST['description'];
		$jsondata=stripslashes(trim($_POST['jsondata']));
		$data['typeid']=post("typeid","i");
		$data['tpl']=post("tpl",'h');
		$data['funtype']=post("funtype","h");
		if(!json_decode($jsondata,true)){
			$this->goAll("json数据格式出错",1);
		}
		$data['jsondata']=base64_encode($jsondata);
		$data['content']=$_POST['content'];
		$data['imgurl']=post("imgurl","h");
		if($id){
			M("uicompent")->update($data,"id=".$id);
		}else{
			M("uicompent")->insert($data);
		}
		$this->goAll("success");
	}
	
	public function onDelete(){
		$id=get_post("id");
		M("uicompent")->delete("id=".$id);
		$this->goAll("success");
	}
	
	 
	
}
?>